﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;
using ToolUtil;
using zyconfig;

namespace zymain
{
    public partial class FrmCxEiso : Form
    {
        private List<int> DbKayList;
        private List<string> DbJcList;
        public int fxsjm;
        private string fxsjc;
        public string ly;
        public string zdh;
        public string stime;
        public string etime;
        public FrmCxEiso()
        {
            InitializeComponent();
        }

        private void qxBtn_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            base.Close();
        }
        public void AddDbList()
        {
            this.fxsKay.Items.Clear();
            this.DbKayList = new List<int>();
            this.DbKayList.Clear();
            this.DbJcList = new List<string>();
            this.DbJcList.Clear();
            using (DbOperHandler _open = new Common().Doh())
            {
                string sql = "select * from 发行商库";
                _open.Reset();
                _open.SqlCmd = sql;
                DataTable dt = _open.GetDataTable();
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dRow in dt.Rows)
                    {
                        this.fxsKay.Items.Add(dRow["发行商"].ToString().Trim());
                        this.DbJcList.Add(dRow["发行商简称"].ToString());
                        this.DbKayList.Add(Convert.ToInt32(dRow["键码"].ToString()));
                    }
                }
                if (this.fxsKay.Items.Count > 0)
                {
                    this.fxsKay.SelectedIndex = 0;
                    this.fxsjc = this.DbJcList[0].ToString();
                    this.fxsjm = int.Parse(this.DbKayList[0].ToString());
                }
            }
        }
        private void skKay_SelectedIndexChanged(object sender, EventArgs e)
        {
            int selectedIndex = this.fxsKay.SelectedIndex;
            this.fxsjc = this.DbJcList[selectedIndex].ToString();
            this.fxsjm = int.Parse(this.DbKayList[selectedIndex].ToString());
            this.zdhTxt.Text = this.fxsjc.Trim() + DateTime.Now.ToString("yyyyMMddHHss");
        }
        private void FrmCxEiso_Load(object sender, EventArgs e)
        {
            DateTime year = DateTime.Now.AddDays(180);
            DateChoser.AddTo(this.sTime);
            DateChoser.AddTo(this.eTime, year);
            this.lyKay.SelectedIndex = 0;
            this.AddDbList();
            this.zdh = this.zdhTxt.Text.Trim();
            if (string.IsNullOrEmpty(zdh))
                this.zdhTxt.Text = this.fxsjc.Trim() + DateTime.Now.ToString("yyyyMMddHHss");
        }

        private void saveBtn_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(zdh))
                this.zdh = this.fxsjc.Trim() + DateTime.Now.ToString("yyyyMMddHHss");
            this.stime = this.sTime.Text.Trim();
            this.etime = this.eTime.Text.Trim();
            this.ly = this.lyKay.Text.Trim();
            DialogResult = DialogResult.OK;
            base.Close();
        }
    }
}
